<!--
 * @Author: xuzehan 123@qq.com
 * @Date: 2023-04-11 14:14:15
 * @LastEditors: xuzehan 935351619@qq.com
 * @LastEditTime: 2024-05-28 14:43:39
 * @FilePath: \ant-design-vue-jeecg-master\src\views\taskManagement\taskAllocation.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class='taskAllocation'>
    <a-collapse v-model='activeKey'>
      <a-collapse-panel key='1' header='资源分配'>
        <h2>
          <!-- 指控车资源分配 -->
          星指链路模式及资源配置
          <!-- <a-button @click="handleConfig" type="primary" style="margin-left: 10px">配置详情</a-button> -->
        </h2>

        <div style='display: flex;border:1px solid'>
          <a-card title='星指链路模式控制' style='width:70%'>
            <div slot='extra'>
              <a-popconfirm overlayClassName='poperLayTable' title='确定发送配置吗?'
                @confirm='() => sendStarFingerLinkModeControl()'>
                <a-button type='primary'>发送</a-button>
              </a-popconfirm>
            </div>

            <a-form-model layout='inline' :model='formInline' :label-col='labelCol1' :wrapper-col='wrapperCol1'>
              <a-row>
                <a-col :span='12'>
                  <a-form-model-item label='上行速率模式'>
                    <a-select v-model='formInline.uplinkRateMode' default-value='00' style='width: 180px'>
                      <a-select-option value='0000'>BPSK-上行640kbps</a-select-option>
                      <a-select-option value='1111'>QPSK-上行1280kbps</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>
                <a-col :span='12'>
                  <a-form-model-item label='下行速率模式'>
                    <a-select v-model='formInline.downlinkRateMode' default-value='0000' style='width: 180px'>
                      <a-select-option value='0000'>BPSK-下行3.2Mbps</a-select-option>
                      <a-select-option value='1111'>QPSK-下行6.4Mbps</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>

              </a-row>

              <a-row>
                <a-col :span='12'>
                  <a-form-model-item label='上行跳频控制'>
                    <a-select v-model='formInline.uplinkFrequencyHoppingControl' default-value='0000'
                      style='width: 180px'>
                      <a-select-option value='0000'>上行定频</a-select-option>
                      <a-select-option value='1111'>上行跳频</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>
                <a-col :span='12'>
                  <a-form-model-item label='下行跳频控制'>
                    <a-select v-model='formInline.downlinkFrequencyHoppingControl' default-value='0000'
                      style='width: 180px'>
                      <a-select-option value='0000'>下行定频</a-select-option>
                      <a-select-option value='1111'>下行跳频</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span='12'>
                  <a-form-model-item label='链路工作模式'>
                    <a-select default-value='00' v-model='formInline.workingMode' style='width: 180px'>
                      <a-select-option value='00'>交换工作模式</a-select-option>
                      <a-select-option value='FF'>自测环境模式</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-form-model>
          </a-card>
          <div style='width:30%;padding: 15px;'>
            <!-- 通联业务处理器星指链路模式控制 -->
            <a-descriptions title='当前遥测信息' size='small' :column='1'>
              <a-descriptions-item :label="item.paramName ? item.paramName : '' + '(' + item.paramCode + ')'"
                v-for='item in descList' :key='item.label'>
                {{ item.paramOriginalValue }}
              </a-descriptions-item>

            </a-descriptions>
          </div>
        </div>
        <div style='display: flex;border:1px solid'>
          <a-card title='星指链路通信频点配置' style='width:70%' class='flex-card'>
            <template slot='actions' class='ant-card-actions'>
              <!-- <a-icon key="setting" type="setting" />
              <a-icon key="edit" type="edit" /> -->
              <!-- <a-icon key="ellipsis" type="ellipsis" /> -->
              <!--              <a-popconfirm overlayClassName='poperLayTable' title='确定发送配置吗?'-->
              <!--                            @confirm="() => sendNoFlowSendPackage3('修改ka接收机和ka上变频器')">-->
              <!--                <a-button type='primary' style='float:right;margin-right:50px' @click='updateKaReceiverAndKaUpConverterPreAllocInfo()'>发送</a-button>-->
              <!--              </a-popconfirm>-->
              <a-button type='primary' style='float:right;margin-right:50px'
                @click='updateKaReceiverAndKaUpConverterPreAllocInfo()'>确认</a-button>

            </template>
            <a-card title='星指上行通信频点'>
              <div slot='extra'>
                <a-popconfirm overlayClassName='poperLayTable' title='确定发送配置吗?'
                  @confirm="() => sendNoFlowSendPackage3('星指上行通信频点')" slot='extra'>
                  <a-button type='primary'>发送</a-button>
                </a-popconfirm>
              </div>


              <div class='flex-center'>
                <a-select v-model='formUp.receiver' style='width: 150px' @change='handleChange'>
                  <a-select-option value='1'>
                    Ka接收机1
                  </a-select-option>
                  <a-select-option value='2'>
                    Ka接收机2
                  </a-select-option>
                  <a-select-option value='3'>
                    Ka接收机3
                  </a-select-option>
                </a-select>
                <a-select style='width: 150px' v-model='formUp.satelliteUpCvCf'>
                  <a-select-option value='30.36'>30.36GHz</a-select-option>
                  <a-select-option value='30.56'>30.56GHz</a-select-option>
                  <a-select-option value='30.76'>30.76GHz</a-select-option>
                  <a-select-option value='30.96'>30.96GHz</a-select-option>
                  <a-select-option value='31.16'>31.16GHz</a-select-option>
                  <a-select-option value='31.36'>31.36GHz</a-select-option>
                  <a-select-option value='31.56'>31.56GHz</a-select-option>
                </a-select>
                <!-- <a-select default-value="add" v-model="formUp.instructionType" style="width: 130px" @change="handleChange">
                  <a-select-option value="add">
                    频率加指令
                  </a-select-option>
                  <a-select-option value="pre">
                    频率减指令
                  </a-select-option>
                </a-select> -->
                <!-- <a-input-number
                  v-model="formUp.packageGridValue"
                    :max="255"
                    :MIN="0"
                  style="width: 130px"
                /> -->
              </div>
            </a-card>
            <a-card title='星指下行通信频点'>
              <div slot='extra'>
                <a-popconfirm overlayClassName='poperLayTable' title='确定发送配置吗?'
                  @confirm="() => sendNoFlowSendPackage3('星指下行通信频点')">
                  <a-button type='primary'>发送</a-button>
                </a-popconfirm>
              </div>

              <!-- <a-button type="primary"@click="sendNoFlowSendPackage3('星指下行通信频点')">发送</a-button> -->
              <div class='flex-center'>
                <a-select v-model='formDown.frequencyConverter' style='width: 150px' @change='handleChange'>
                  <a-select-option value='1'>
                    Ka上变频器1
                  </a-select-option>
                  <a-select-option value='2'>
                    Ka上变频器2
                  </a-select-option>
                  <a-select-option value='3'>
                    Ka上变频器3
                  </a-select-option>
                  <a-select-option value='4'>
                    Ka上变频器4
                  </a-select-option>
                </a-select>
                <a-select style='width: 150px' v-model='formDown.satelliteDownCvCf'>
                  <a-select-option value='20.16'>20.16GHz</a-select-option>
                  <a-select-option value='20.36'>20.36GHz</a-select-option>
                  <a-select-option value='20.56'>20.56GHz</a-select-option>
                  <a-select-option value='20.76'>20.76GHz</a-select-option>
                  <a-select-option value='20.96'>20.96GHz</a-select-option>
                  <a-select-option value='21.16'>21.16GHz</a-select-option>
                  <a-select-option value='21.36'>21.36GHz</a-select-option>
                </a-select>
                <!-- <a-select default-value="add"   v-model="formDown.instructionType" style="width: 130px" @change="handleChange">
                        <a-select-option value="add">
                          频率加指令
                        </a-select-option>
                        <a-select-option value="pre">
                          频率减指令
                        </a-select-option>
                </a-select> -->
                <!-- <a-input-number
                      v-model="formDown.packageGridValue"
                      :max="255"
                      :MIN="0"
                      style="width: 130px"
                    /> -->
              </div>
            </a-card>

          </a-card>

          <div style='width:30%;padding: 15px;'>
            <a-descriptions title='当前遥测信息' size='small' :column='1'>
              <a-descriptions-item :label="item.paramName ? item.paramName : '' + '(' + item.paramCode + ')'"
                v-for='item in descList1' :key='item.label'>
                {{ item.paramOriginalValue }}
              </a-descriptions-item>
            </a-descriptions>
          </div>
        </div>
        <a-card title='星指上行链路通信时隙配置' style='width: 100%'>
          <a-form-model :model='form' :label-col='labelCol1' :wrapper-col='wrapperCol1'>
            <a-row>
              <a-col :span='20'>
                <a-form-model-item label='指控车选择'>
                  <a-select v-model='form1.speed' placeholder='请选择' @change='changeCar'>
                    <a-select-option :value='item.identificationCode' v-for='item in result' :key='item.id'>{{ item.name
                      }} ({{
      item.identificationCode }})
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
            </a-row>
            <!-- <a-row>
              <a-col :span="20">
                <a-form-model-item label="星指上行链路工作参数配置">
                  <a-input-number
                    v-model="formUp.packageGridValue"
                    :max="1920"
                    :style="{ width: '100%' }"
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="2">
                <a-form-model-item>
                  <a-button
                    @click="handleValues('9-星指上行链路接收机变频器频点号')"
                    type="primary"
                    style="margin-left: 10px"
                  >发送</a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="星指下行链路工作参数配置">
                  <a-input-number
                    v-model="form.packageGridValue"
                    :max="1920"
                    :style="{ width: '100%' }"
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="2">
                <a-form-model-item>
                  <a-button
                    @click="handleValues('8-星指下行链路接收机变频器频点号')"
                    type="primary"
                    style="margin-left: 10px"
                  >发送</a-button>
                </a-form-model-item>
              </a-col>

            </a-row>-->
            <a-row>
              <a-col :span='20'>
                <a-form-model-item label='同步起跳数'>
                  <div>
                    <a-checkbox-group @change='onChange' defaultChecked>
                      <div class='TB'>
                        <!-- <h3 :style="{ width: '130px' }">同步时隙起跳数</h3> -->
                        <a-radio-group :disabled='disabledEdit' v-model='JumpSignal' @change='onChange1'
                          button-style='solid' :style="{ width: 'calc(100%)' }">
                          <a-radio-button v-for='(item, index) in btnList' :key='index' :disabled='item.disabled'
                            :value='item.label'
                            :style="{ width: '25%', height: '40px', 'line-height': '40px', 'text-align': 'center' }">{{
      item.label }}
                          </a-radio-button>
                          <!-- <a-radio-button
                            :value="1"
                            :style="{ width: '25%', height: '40px', 'line-height': '40px', 'text-align': 'center' }"
                          >1</a-radio-button>
                          <a-radio-button
                            :value="2"
                            :style="{ width: '25%', height: '40px', 'line-height': '40px', 'text-align': 'center' }"
                          >2</a-radio-button>
                          <a-radio-button
                            :value="3"
                            :style="{ width: '25%', height: '40px', 'line-height': '40px', 'text-align': 'center' }"
                          >3</a-radio-button>
                          <a-radio-button
                            :value="4"
                            :style="{ width: '25%', height: '40px', 'line-height': '40px', 'text-align': 'center' }"
                          >4</a-radio-button>-->
                        </a-radio-group>
                      </div>

                      <!--   <a-row>
                        <pool1
                          ref="pool1"
                          :group="true"
                          :data="JSON.stringify(poolData)"
                          :small="2"
                        />
                      </a-row>-->
                    </a-checkbox-group>
                  </div>
                </a-form-model-item>
              </a-col>
              <!-- <a-col :span="2">
                <a-form-model-item>
                  <a-button
                    @click="handleValues('10星指上行链路资源分配信息')"
                    type="primary"
                    style="margin-left: 10px"
                  >确定</a-button>
                  <a-button @click="savePool" type="primary" style="margin-left: 10px"> 配置</a-button> //不要
                </a-form-model-item>
              </a-col>-->
              <!-- <a-col :span="2">
              <a-form-model-item>
                <a-button @click="handleSend('6指挥车时隙分配信息')" type="primary" style="margin-left: 10px">
                  发送</a-button
                >
              </a-form-model-item>
              </a-col>-->
            </a-row>
            <a-row>
              <a-col :span='20'>
                <a-form-model-item label='具体时隙分配'>
                  <pool1 ref='pool1' :group='true' :data='JSON.stringify(poolData)' :small='2' />
                </a-form-model-item>
              </a-col>
              <a-col :span='2'>
                <a-form-model-item>
                  <a-button @click="handleValues('10星指上行链路资源分配信息')" type='primary' style='margin-left: 10px'
                    :disabled='disabledEdit'>确定
                  </a-button>
                  <!-- <a-button @click="savePool" type="primary" style="margin-left: 10px"> 配置</a-button> -->
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </a-card>
      </a-collapse-panel>
      <a-collapse-panel key='2' header='控制指令发送及响应'>
        <!-- <a-form-model :model="form1" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-row>
            <a-col :span="16">
              <a-form-model-item label="星弹上行链路工作参数配置">
                <a-select v-model="form1.region" placeholder="请选择" allowClear>
                  <a-select-option value="1"> 指控车1 </a-select-option>
                  <a-select-option value="2"> 指控车2 </a-select-option>
                  <a-select-option value="3"> 指控车3 </a-select-option>
                  <a-select-option value="4"> 指控车4 </a-select-option>
                </a-select>

                <pool ref="pool" :total="1920" :small="0" v-if="form1.region" />
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-form-model-item>
                <a-button @click="creatInstruct" type="primary"> 发送</a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="16">
              <a-form-model-item label="星弹下行链路工作参数配置">
                <a-select v-model="form1.speed" placeholder="请选择">
                  <a-select-option value="32kbps"> 32kbps </a-select-option>
                  <a-select-option value="96kbps"> 96kbps </a-select-option>
                  <a-select-option value="256kbps"> 256kbps </a-select-option>
                  <a-select-option value="1024kbps"> 1024kbps </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-form-model-item>
                <a-button @click="creatInstruct" type="primary"> 发送</a-button>
              </a-form-model-item>
            </a-col>
          </a-row>

        </a-form-model>-->
      </a-collapse-panel>
    </a-collapse>
    <creat-instruct ref='creatInstruct' />
    <configModal ref='configModal' />
  </div>
</template>

<script>
import { processDefineKey } from '@/api/processDefineKey'
import CascaderSelect from './modules/Cascader.vue'
import creatInstruct from './modules/createInstruct'
import { getAction, httpAction } from '@/api/manage.js'
import configModal from './modules/confidModal.vue'
//  <!-- 资源池 -->
import pool1 from './modules/resourcePool1.vue'
import { Turns, sum } from '@/utils/util.js'

export default {
  components: { creatInstruct, pool1, CascaderSelect, configModal },
  // props: ['fightDemandId'],
  data() {
    return {
      fightDemandId: '',
      disabledEdit: false,
      text: `world.`,
      JumpSignal: undefined,
      btnList: [
        { label: 1, disabled: false },
        { label: 2, disabled: false },
        { label: 3, disabled: false },
        { label: 4, disabled: false }
      ],
      poolData: [],
      tabActiveKey: '1',
      activeKey: ['1', '2'],
      formInline: { workingMode: '00' },
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      labelCol1: { span: 10 },
      wrapperCol1: { span: 14 },
      form: { packageGridValue: '' },
      fightForm: { startDate: undefined },
      form1: { packageGridValue: '' },
      formUp: { receiver: '1' },
      formDown: { frequencyConverter: '1' },
      formBall: {},
      resourcesForm: {},
      resourcesList: [],
      resourcesNo: {},
      check: [],
      checkList: [],
      props: { multiple: true },
      ac: [
        { active: 1, disabled: [] },
        { active: 2, disabled: [] },
        { active: 3, disabled: [] },
        { active: 4, disabled: [] }
      ],
      das: null,
      multipleTreeData: [],
      carfightDemandId: '',
      carlist: [],
      descList: [],
      descList1: [],
      result: [],
      url: {
        getByParamCodes: '/telemetryInfo/nmcTelemetryInfo/getByParamCodes',
        doSlotAlloc: '/commandVehicle/nmcCommandVehicle/updateSlotAllocInfo',
        getcarsource: '/commandVehicle/nmcCommandVehicle/getBySpecifyDayOfCommandVehicleExcludeRetiredByFightDemandId',
        carlist: '/commandVehicle/nmcCommandVehicle/queryRunningFightDemandOfCommandVehicle',
        sendPackage: '/channel/nmcChannelInfo/sendPackage',
        getLatestPackageGridValue: '/grid/nmcPackageGridValue/getLatestPackageGridValue',
        getNmcPackageGridValueByCode: '/grid/nmcPackageGridValue/code',
        nmcPackageGridList: '/grid/nmcPackageGrid/list',
        addnmcPackageGridValue: '/grid/nmcPackageGridValue/add', //{"packageGridValue":"22AA","Values":["22","aa"],"packageGridId":"1663806762680139777"}
        noFlowSendPackage3: '/channel/nmcChannelInfo/noFlowSendPackage3',
        doManualSetKaReceiver: '/fightDemand/nmcFightDemand/doManualSetKaReceiver',
        doManualSetKaUpConverter: '/fightDemand/nmcFightDemand/doManualSetKaUpConverter',
        updateKaReceiverAndKaUpConverterPreAllocInfo: '/fightDemand/nmcFightDemand/updateKaReceiverAndKaUpConverterPreAllocInfo'
      }
    }
  },
  watch: {
    activeKey(key) {
      console.log(key)
    }
  },
  created() {
    for (let i = 29; i >= 0; i--) {
      this.poolData.push({ id: 29 - i, check: false, index: i, disabled: false })
      // this.poolData.push({ id: i, check: false, index: 29 - i })
    }
  },
  mounted() {

    this.getYC()
    console.log(processDefineKey, 'this.$route.query.id')
  },
  // activated() {
  //   for (let i = 1; i <= 30; i++) {
  //     this.poolData.push({ id: i, check: false })
  //   }
  // },
  methods: {
    getYC() {
      // {
      //     label: '通联业务处理器星指链路模式控制',对应遥测
      //     correspondingTelemetry: [
      //       { value: 'ZDZA425', label: '通联业务处理器星指链路上行速率模式' },
      //       { value: 'ZDZA426', label: '通联业务处理器星指链路下行速率模式' },
      //       { value: 'ZDZA428', label: '通联业务处理器星指链路上行跳频模式' },
      //       { value: 'ZDZA429', label: '通联业务处理器星指链路下行跳频模式' },
      //     ]
      //   },
      let paramCodeArr = ['ZDZA425', 'ZDZA426', 'ZDZA428', 'ZDZA429']
      getAction(this.url.getByParamCodes, { paramCodes: paramCodeArr.join() }).then(res => {
        if (res.success) {
          // descList.forEach(i => {
          //   let data = res.result.find(j => j.paramCode == i.value)
          //   if (data) descList.find(c => c.value == data.paramCode).paramOriginalValue = data.paramOriginalValue
          // })
          this.descList = res.result
        } else {
          this.$message.error(res.message)
        }
      })
      let paramCodeArr1 = ['VX002', 'VX005', 'VX007', 'ZX528', 'ZX530', 'ZX532', 'ZX534']
      getAction(this.url.getByParamCodes, { paramCodes: paramCodeArr1.join() }).then(res => {
        if (res.success) {
          console.log(res, '----')
          this.descList1 = res.result
        } else {
          this.$message.error(res.message)
        }
      })
    },
    /**
     * 修改ka接收机和ja上变频器的预分配信息
     * @param val
     */
    updateKaReceiverAndKaUpConverterPreAllocInfo(val) {
      let url = this.url.updateKaReceiverAndKaUpConverterPreAllocInfo
      let paramsData = {
        id: this.fightDemandId,
        kaReceiverPreAllocInfo: this.formUp.receiver,
        kaUpConverterPreAllocInfo: this.formDown.frequencyConverter
      }
      httpAction(url, paramsData, 'post').then((res) => {
        if (res.code == 200) {
          this.$message.success('修改成功！')
        } else {
          this.$message.error('修改失败！')
        }
      })
    },
    sendNoFlowSendPackage3(val) {
      let url = ''
      let paramsData
      if (val == '星指上行通信频点') {
        url = this.url.doManualSetKaReceiver
        paramsData = {
          configValue: this.formUp.satelliteUpCvCf,
          receiverNum: this.formUp.receiver
        }
      } else if (val == '星指下行通信频点') {
        url = this.url.doManualSetKaUpConverter
        paramsData = {
          configValue: this.formDown.satelliteDownCvCf,
          kaUpConverterNum: this.formDown.frequencyConverter
        }

      }
      httpAction(url, new URLSearchParams(Object.entries(paramsData)), 'post').then((res) => {
        if (res.code == 200) {
          this.$message.success('发包成功！')
          // this.getValueByCode()
        } else {
          this.$message.error('发包失败！')
        }
      })


      return
      let data = {
        'packageCode': '',
        'serializeItemDtoList': [
          {
            'packageGridCode': '',
            'packageGridValue': ''
          }
        ]
      }

      if (val == '星指上行通信频点') {
        let map = [
          { label: 'Ka接收机1频率加指令', packCode: '70Ka接收机1频率加指令' },
          { label: 'Ka接收机1频率减指令', packCode: '73Ka接收机1频率减指令' },
          { label: 'Ka接收机2频率加指令', packCode: '71Ka接收机2频率加指令' },
          { label: 'Ka接收机2频率减指令', packCode: '74Ka接收机2频率减指令' },
          { label: 'Ka接收机3频率加指令', packCode: '72Ka接收机3频率加指令' },
          { label: 'Ka接收机3频率减指令', packCode: '75Ka接收机3频率减指令' }
        ]
        let str = ''
        str = `Ka接收机${this.formUp.receiver}频率${this.formUp.instructionType == 'add' ? '加' : '减'}指令`
        let packageCode = map.find(i => i.packCode.includes(str)).packCode
        data.packageCode = packageCode
        let packNo = packageCode.match(/(\S*)Ka/)
        data.serializeItemDtoList[0].packageGridCode = packNo[1] + '-频率值'
        data.serializeItemDtoList[0].packageGridValue = this.formUp.packageGridValue
      } else if (val == '星指下行通信频点') {
        let map1 = [
          { packCode: '76Ka上变频器1频率加指令' },
          { packCode: '77Ka上变频器2频率加指令' },
          { packCode: '78Ka上变频器3频率加指令' },
          { packCode: '79Ka上变频器4频率加指令' },
          { packCode: '80Ka上变频器1频率减指令' },
          { packCode: '81Ka上变频器2频率减指令' },
          { packCode: '82Ka上变频器3频率减指令' },
          { packCode: '83Ka上变频器4频率减指令' }
        ]
        let str1 = ''
        str1 = `Ka上变频器${this.formDown.frequencyConverter}频率${this.formDown.instructionType == 'add' ? '加' : '减'}指令`
        // console.log(str1,map1.find(it=>it.packCode.includes(str1)));
        map1.forEach(item => {
          console.log(item.packCode, '-------', str1)
          if (item.packCode.includes(str1)) {
            console.log(item, '********')
            data.packageCode = item.packCode
          }
        })
        // let packageCode1=map1.find(i=>i.packCode.includes(str1)).packCode
        // data.packageCode=packageCode1
        let packNo1 = data.packageCode.match(/(\S*)Ka/)
        console.log(data.packageCode, 'packNo1', packNo1)
        data.serializeItemDtoList[0].packageGridCode = packNo1[1] + '-频率值'
        data.serializeItemDtoList[0].packageGridValue = this.formDown.packageGridValue

      }
      httpAction(this.url.noFlowSendPackage3, data, 'post').then((res) => {
        if (res.code == 200) {
          this.$message.success('发包成功！')
          // this.getValueByCode()
        } else {
          this.$message.error('发包失败！')
        }
      })
    },
    sendStarFingerLinkModeControl() {
      console.log(this.formInline, '=========')
      let data = {
        'packageCode': '86通联业务处理器星指链路模式控制',
        'serializeItemDtoList': [
          {
            'packageGridCode': '86-跳频控制',
            'packageGridValue': Turns(this.formInline.uplinkFrequencyHoppingControl + this.formInline.downlinkFrequencyHoppingControl, 16)
          },
          {
            'packageGridCode': '86-工作模式',
            'packageGridValue': this.formInline.workingMode
          },
          {
            'packageGridCode': '86-速率模式',
            'packageGridValue': Turns(this.formInline.uplinkRateMode + this.formInline.downlinkRateMode, 16)
          }
        ]
      }

      httpAction(this.url.noFlowSendPackage3, data, 'post').then((res) => {
        if (res.code == 200) {
          this.$message.success('发包成功！')
          // this.getValueByCode()
        } else {
          this.$message.error('发包失败！')
        }
      })
    },
    init(record, disabledEdit) {
      this.disabledEdit = disabledEdit
      this.fightDemandId = record.id
      this.formUp.satelliteUpCvCf = record.satelliteUpCvCf
      this.formDown.satelliteDownCvCf = record.satelliteDownCvCf
      this.formUp.receiver = record.kaReceiverPreAllocInfo;
      this.formDown.frequencyConverter = record.kaUpConverterPreAllocInfo;
    },
    emptyData() {
      this.disabledEdit = false
      this.fightDemandId = ''
      this.form = { packageGridValue: '' }
      this.formUp = { receiver: '1' }
      this.formDown = { frequencyConverter: '1' }
      this.formInline = { workingMode: '00' }
      // this.formUp = { Values: [], packageGridValue: '' }
      this.JumpSignal = undefined
      this.poolData = []
      this.form1 = {}
      this.btnList.map(function (item, index, input) {
        return item.disabled = false
      })
      this.$refs.pool1.subData.forEach(i => {
        i.check = false
        i.disabled = false
      })
    },
    setSlot(carId) {
      this.btnList.forEach(item => {
        item.disabled = false
      })
      let occupyJump = []//所有占用的起跳
      let occupySlot = []//所有占用的时隙
      this.result.forEach(el => {
        occupySlot.push(el.allocatedSlotInfo.split(','))
        occupyJump.push(el.allocatedSlotJumpSignal)
      })
      let select = this.result.find(i => i.identificationCode == carId)
      if (select) {
        let nmcNcvAllocInfo = select//选中的车信息
        this.JumpSignal = nmcNcvAllocInfo.allocatedSlotJumpSignal//同步起跳
        let allocatedSlotInfo = nmcNcvAllocInfo.allocatedSlotInfo//该车的时隙
        let arr = allocatedSlotInfo.split(',')
        if (arr.length) {
          arr.forEach(i => {
            this.$refs.pool1.subdown({ id: Number(i) * 6, check: false })
          })
        }
        //设置禁用
        let a = occupyJump.filter(item => item !== nmcNcvAllocInfo.allocatedSlotJumpSignal)
        a.forEach(i => {
          this.btnList.find(item => item.label == i).disabled = true
        })
        let b = occupySlot.filter(i => i != allocatedSlotInfo)
        let arr1 = b.flat()
        if (arr1.length) {
          arr1.forEach(i => {
            this.$refs.pool1.disabledDown({ id: Number(i) * 6, check: false, disabled: false })
          })
        }
        // this.$refs.pool1.disabledDown({ id: Number(i) * 6, check: false, disabled: false, })
      } else {
        this.JumpSignal = undefined
        //设置禁用
        occupyJump.forEach(i => {
          this.btnList.find(item => item.label == i).disabled = true
        })
        let arr1 = occupySlot.flat()
        if (arr1.length) {
          arr1.forEach(i => {
            this.$refs.pool1.disabledDown({ id: Number(i) * 6, check: false, disabled: false })
          })
        }
      }

    },
    getcarsource() {
      this.getYC()
      getAction(this.url.getcarsource, { fightDemandId: this.fightDemandId }).then(res => {
        // console.log(res, 'res')
        if (res.success) {
          this.result = res.result
          // console.log(this.result)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    changeCar(val, row) {
      console.log(val, row)
      this.carfightDemandId = this.result.find(i => i.identificationCode == val).fightDemandId
      this.$refs.pool1.subData.forEach(i => {
        i.check = false
        i.disabled = false
      })
      this.setSlot(val)


      // return
      // let obj2 = { gridCode: '10-分配给指挥车的具体时隙号', packageCode: '10星指上行链路资源分配信息', businessId: val, processDefineKey: processDefineKey.SatelliteToCommandVehicleUpLinkResourceAllocHandleImplKey }
      // getAction(this.url.getLatestPackageGridValue, obj2).then((res) => {
      //   if (res.result && res.result.packageGridValue) {
      //     let temp = res.result.packageGridValue
      //     let data = Turns(temp.slice(8, temp.length), 2).split('')
      //     let reslut = data.slice(2, data.length)
      //     reslut.forEach((i, index) => {
      //       if (i == 1) {
      //         this.poolData.find((el) => el.id == index).check = true
      //       }
      //     })
      //     this.$refs.pool1.subData = JSON.parse(JSON.stringify(this.poolData))
      //   } else {
      //     this.poolData.forEach((item) => {
      //       item.check = false
      //     })
      //     this.$refs.pool1.subData = JSON.parse(JSON.stringify(this.poolData))
      //   }
      // })
    },
    getCarList() {
      getAction(this.url.carlist).then((res) => {
        this.carlist = res.result
      })
    },
    handleConfig() {
      this.$refs.configModal.showModal({}, 'car')
    },
    hex2int(hex) {
      //16进制转10进制
      if (!hex) return
      var len = hex.length,
        a = new Array(len),
        code
      for (var i = 0; i < len; i++) {
        code = hex.charCodeAt(i)
        if (48 <= code && code < 58) {
          code -= 48
        } else {
          code = (code & 0xdf) - 65 + 10
        }
        a[i] = code
      }
      return a.reduce(function (acc, c) {
        acc = 16 * acc + c
        return acc
      }, 0)
    },
    // 工程量值根据Code回显
    getValueByCode() {
      const that = this
      let obj = {
        gridCode: '8-星指下行链路接收机变频器频点号',
        packageCode: '8星指下行链路变频器频点信息',
        processDefineKey: processDefineKey.SatelliteToCommandVehicleDownFrequencyConfHandleImplKey
      }
      getAction(this.url.getLatestPackageGridValue, obj).then((res) => {
        let temp = res.result.packageGridValue
        this.form.packageGridValue = this.hex2int(temp)
        console.log(res, '8-星指下行链路接收机变频器频点号')
      })
      let obj1 = {
        gridCode: '9-星指上行链路接收机变频器频点号',
        packageCode: '9星指上行链路变频器频点信息',
        processDefineKey: processDefineKey.SatelliteToCommandVehicleDownFrequencyConfHandleImplKey
      }
      getAction(this.url.getLatestPackageGridValue, obj1).then((res) => {
        let temp = res.result.packageGridValue
        this.formUp.packageGridValue = this.hex2int(temp)
        console.log(res, '9----星指下行链路接收机变频器频点号')
      })

    },
    // 逆序，选择状态转换成0/1
    reverseAndConvert(subData) {
      var newArray = [] //新建的空数组是为了保存翻转后的数组的
      for (var i = 0; i < subData.length; i++) {
        if (subData[i].check) {
          subData[i].data = 0
        } else {
          subData[i].data = 1
        }
        subData[i].id = i + 1
        newArray.push(subData[i]) //利用unshift 将原数组重新插入newArray[]数组中
      }
      return newArray
    },
    handleValues(val) {
      let params = {
        nmcPackageGridValues: [
          {
            batchId: '',
            gridCode: '',
            packageGridValue: ''
          }
        ],
        packageCode: ''
      }
      if (val == '9-星指上行链路接收机变频器频点号') {
        params.packageCode = '9星指上行链路变频器频点信息'
        params.nmcPackageGridValues[0].gridCode = '9-星指上行链路接收机变频器频点号'
        params.nmcPackageGridValues[0].packageGridValue = this.formUp.packageGridValue.toString(16).padStart(4, 0)
        httpAction(this.url.sendPackage, params, 'post').then((res) => {
          if (res.code == 200) {
            this.$message.success('发包成功！')
            this.getValueByCode()
          } else {
            this.$message.error('发包失败！')
          }
        })
      }
      if (val == '8-星指下行链路接收机变频器频点号') {
        params.packageCode = '8星指下行链路变频器频点信息'
        params.nmcPackageGridValues[0].gridCode = '8-星指下行链路接收机变频器频点号'
        // params.nmcPackageGridValues[0].packageGridValue = this.formInline.localOscillator + this.Turns(aaa, 16)

        params.nmcPackageGridValues[0].packageGridValue = this.form.packageGridValue.toString(16).padStart(4, 0)
        httpAction(this.url.sendPackage, params, 'post').then((res) => {
          if (res.code == 200) {
            this.$message.success('发包成功！')
            this.getValueByCode()
          } else {
            this.$message.error('发包失败！')
          }
        })
      }

      if (val == '10星指上行链路资源分配信息') {
        if (!this.form1.speed) {
          this.$message.error(`请选择指控车！`)
          return
        }
        if (!this.JumpSignal) {
          this.$message.error(`请选择起跳数！`)
          return
        }
        let subData = this.$refs.pool1.subData
        let str = []
        if (subData[0].check) {
          str.push('0')
        }
        if (subData[6].check) {
          str.push('1')
        }
        if (subData[12].check) {
          str.push('2')
        }
        if (subData[18].check) {
          str.push('3')
        }
        if (subData[24].check) {
          str.push('4')
        }

        if (!str.length) {
          this.$message.error(`请选择时隙分配！`)
          return
        }

        if (str.length > 1 && !this.isContinuityNum(str)) {
          this.$message.error(`请选择连续的进行时隙分配！`)
          return
        }
        let data = {
          'allocatedSlotInfo': str.join(),
          'allocatedSlotJumpSignal': this.JumpSignal,
          'identificationCode': this.form1.speed,
          'fightDemandId': this.carfightDemandId
        }
        console.log(data, 'data')
        // return
        httpAction(this.url.doSlotAlloc, data, 'post').then((res) => {
          if (res.code == 200) {
            this.$message.success(res.message)
            this.getcarsource()
          } else {
            this.$message.error(res.message)
          }
        })
        // subData.map((i) => (i.data = i.check ? 1 : 0))
        // let str = ''
        // subData.forEach((i) => {
        //   str += i.data
        // })
        // let count = sum(str, '1') //6-分配给车1的时隙个数
        // let strs = str.padStart(64, 0)
        // let temp = Turns(strs, 16) //6-分配给车1的时隙号
        // this.resourcesForm.packageGridValue = temp
        // if (count > 12 || count < 5) {
        //   this.$message.error('最多选择两个时隙资源块，最少选择一个！！！')
        //   return
        // }

        // let params1 = {
        //   nmcPackageGridValues: [
        //     {
        //       gridCode: '10-分配给指挥车的时隙个数',
        //       packageGridValue: count,
        //     },
        //     {
        //       gridCode: '10-分配给指挥车的具体时隙号',
        //       packageGridValue: temp,
        //     },
        //     {
        //       gridCode: '10-指挥车识别码',
        //       packageGridValue: this.form1.speed,
        //     },
        //   ],
        //   packageCode: '10星指上行链路资源分配信息',
        // }

      }
    },
    //判断连续
    isContinuityNum(num) {
      let array = []
      if (num instanceof Array) {
        array = [...num]
      } else {
        array = Array.from(num.toString())//转换为数组
      }

      var i = array[0]
      var isContinuation = true
      for (var e in array) {
        if (array[e] != i) {
          isContinuation = false
          break
        }
        i++
      }
      console.log(isContinuation, 'isContinuation')
      return isContinuation
    },
    changeCarCounts(val) {
      this.multipleTreeData = []
      let children = []
      for (let i = 1; i <= 32; i++) {
        children.push({
          id: `${i}-1`,
          value: `导弹${i}`,
          label: `导弹${i}`
        })
      }
      for (let i = 1; i <= val; i++) {
        this.multipleTreeData.push({
          id: i,
          value: `指挥车${i}`,
          label: `指挥车${i}`,
          children: [...children]
        })
      }
    },

    creatInstruct() {
    },
    handleCreatInstruct() {
      //指令一键生成
      this.$refs.creatInstruct.showModal(this.fightForm)
      console.log(this.fightForm)
    },
    handleChange(value) {
      console.log(`selected ${value}`)
    },
    onSubmit() {
      console.log(this.form)
    },
    onChange1(checkedValues) {
      console.log('checked = ', checkedValues)
    },
    onChange(e) {
      this.resourcesList.forEach((i) => {
        if (i.active == this.tabActiveKey) {
          i.disabled = false
        }
        e.forEach((item) => {
          if (i.label == item) {
            i.disabled = true
            i.active = this.tabActiveKey
          }
        })
      })
    },
    callback(key) {
      this.tabActiveKey = key
      this.ac.forEach((i, index) => {
        if (i.active == this.tabActiveKey) {
          this.ac.splice(index, 1)
        }
      })
    },
    filter(val) {
      if (this.checkList.indexOf(val) != -1) {
        return true
      } else {
        return false
      }
    }
  }
}
</script>

<style lang='less'>
.flex-card .ant-card-body {

  display: flex;

  .ant-card {
    width: 49%;
  }

  // padding: 0;
}

.flex-center {
  display: flex;
  // justify-content: center;
  align-items: center;
}

.ant-descriptions-title {
  color: #fff;
  text-align: center;
}

.taskAllocation .ant-descriptions-item-label {
  font-size: 16px !important;
}

.ant-descriptions-item-content {
  font-size: 16px !important;
}

.TB {
  display: flex;
}

.taskAllocation {
  .ant-checkbox-group {

    // height: 300px;
    // line-height: 0.9;
    .ant-checkbox-wrapper {
      margin: 0;
    }

    .ant-col {
      width: auto;
      margin: 0;
    }
  }
}

.tabs .ant-row {
  width: 600px;

  .ant-checkbox-inner {
    width: 40px !important;
    height: 40px !important;
    text-align: center;

    &::after {
      width: 7px;
      height: 14px;
      left: 35%;
    }
  }
}

.ant-checkbox-inner {
  /* background-color: red !important; */
  border-color: #6e6e6e !important;
}

.ant-form-item-control {
  line-height: 0 !important;
}

.ant-card-actions {
  background: transparent !important;
  border: none !important;
}
</style>
